package by.gravity.provider;

import java.sql.SQLException;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class GrsuGsonSheduleProvider implements GsonSheduleProvider {

	private GrsuSheduleProvider provider;

	public GrsuGsonSheduleProvider() {
		provider = new GrsuSheduleProvider();
	}

	@Override
	public String getSpeciality() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
		return convertToJson(provider.getSpeciality());
	}

	@Override
	public String getKursList(String speciality) throws InstantiationException, IllegalAccessException, ClassNotFoundException,
			SQLException {
		return convertToJson(provider.getKurs(speciality));
	}

	@Override
	public String getGroupsList(String specialityName, String kursName) throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
		return convertToJson(provider.getGroups(specialityName, kursName));
	}

	@Override
	public String getPairs(String specialityName, String kursName, String groupName, long weekStart) throws InstantiationException,
			IllegalAccessException, ClassNotFoundException, SQLException {
		return convertToJson(provider.getPairs(specialityName, kursName, groupName, weekStart));
	}

	private String convertToJson(Object object) {
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
		return gson.toJson(object);
	}

}
